﻿<UserControl x:Class="Big3.Hitbase.CatalogView.AlbumView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:hc="clr-namespace:Big3.Hitbase.Controls;assembly=Controls"
    xmlns:local="clr-namespace:Big3.Hitbase.CatalogView"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <local:LengthConverter x:Key="lengthConverter" />

        <!-- Wait Indicator -->
        <Color x:Key="FilledColor" A="255" B="155" R="155" G="155"/>
        <Color x:Key="UnfilledColor" A="0" B="155" R="155" G="155"/>
        <Storyboard x:Key="Animation0" FillBehavior="Stop" BeginTime="00:00:00.0" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_00" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Animation1" BeginTime="00:00:00.1" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_01" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Animation2" BeginTime="00:00:00.2" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_02" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Animation3" BeginTime="00:00:00.3" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_03" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Animation4" BeginTime="00:00:00.4" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_04" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Animation5" BeginTime="00:00:00.5" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_05" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Animation6" BeginTime="00:00:00.6" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_06" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
        <Storyboard x:Key="Animation7" BeginTime="00:00:00.7" RepeatBehavior="Forever">
            <ColorAnimationUsingKeyFrames Storyboard.TargetName="_07" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">
                <SplineColorKeyFrame KeyTime="00:00:00.0" Value="{StaticResource FilledColor}"/>
                <SplineColorKeyFrame KeyTime="00:00:00.8" Value="{StaticResource UnfilledColor}"/>
            </ColorAnimationUsingKeyFrames>
        </Storyboard>
    </UserControl.Resources>
    <UserControl.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Animation0}"/>
            <BeginStoryboard Storyboard="{StaticResource Animation1}"/>
            <BeginStoryboard Storyboard="{StaticResource Animation2}"/>
            <BeginStoryboard Storyboard="{StaticResource Animation3}"/>
            <BeginStoryboard Storyboard="{StaticResource Animation4}"/>
            <BeginStoryboard Storyboard="{StaticResource Animation5}"/>
            <BeginStoryboard Storyboard="{StaticResource Animation6}"/>
            <BeginStoryboard Storyboard="{StaticResource Animation7}"/>
        </EventTrigger>
    </UserControl.Triggers>

    <Grid KeyDown="grid_KeyDown">
        <ItemsControl x:Name="dataGrid1" ScrollViewer.VerticalScrollBarVisibility="Auto" VirtualizingStackPanel.IsVirtualizing="True" ScrollViewer.CanContentScroll="true" VirtualizingStackPanel.VirtualizationMode="Recycling" AlternationCount="2">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <local:VirtualizingTilePanel></local:VirtualizingTilePanel>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.Template>
                <ControlTemplate>
                    <ScrollViewer Background="White" x:Name="ScrollViewer" Padding="{TemplateBinding Padding}">
                        <ItemsPresenter />
                    </ScrollViewer>
                </ControlTemplate>
            </ItemsControl.Template>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Border Name="ItemContainer">
                    <StackPanel MouseLeftButtonDown="GridRow_MouseLeftButtonDown"  ContextMenuOpening="GridRow_ContextMenuOpening"  Name="GridRow" Background="Transparent" Orientation="Horizontal" >
                        <Grid Width="300" >
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="120" />
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                                <Image x:Name="ImagePlayNow" SnapsToDevicePixels="True" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,1,0,0" Stretch="None" ToolTip="Sofort spielen" Source="Images/PreListen.png" MouseEnter="ImagePlayNow_MouseEnter" MouseLeave="ImagePlayNow_MouseLeave" MouseLeftButtonDown="ImagePlayNow_MouseLeftButtonDown" />
                                <Image Grid.Column="0" VerticalAlignment="Top" Source="{Binding Path=Image}" Width="100" Height="100" Margin="10 5 10 10" >
                                <Image.Effect>
                                    <DropShadowEffect Color="LightGray" />
                                </Image.Effect>
                            </Image>
                            <StackPanel Orientation="Vertical" Grid.Column="1">
                                <TextBlock Text="{Binding Path=Artist}" TextTrimming="CharacterEllipsis" Margin="0 3 0 3" />
                                <TextBlock Text="{Binding Path=Title}"  TextTrimming="CharacterEllipsis" Margin="0 3 0 3" />
                                <TextBlock Text="{Binding Path=Genre}"  TextTrimming="CharacterEllipsis" Margin="0 3 0 3" />
                                <TextBlock Text="{Binding Path=Year}"  TextTrimming="CharacterEllipsis" Margin="0 3 0 3" />
                                <TextBlock Text="{Binding Path=ArchiveNumber}"  TextTrimming="CharacterEllipsis" Margin="0 3 0 3" />
                                </StackPanel>
                        </Grid>

                        <Grid>
                            <ItemsControl ScrollViewer.HorizontalScrollBarVisibility="Hidden" ItemsSource="{Binding Path=Tracks}" BorderThickness="0" SnapsToDevicePixels="True">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Grid SnapsToDevicePixels="True" Name="GridControl" Background="Transparent" Height="18">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="70" />
                                                <ColumnDefinition Width="50" />
                                                <ColumnDefinition Width="200" />
                                                <ColumnDefinition Width="50" />
                                                <ColumnDefinition Width="130" />
                                                <ColumnDefinition Width="150" />
                                                <ColumnDefinition Width="150" />
                                            </Grid.ColumnDefinitions>
                                            <StackPanel x:Name="PlayButtons" SnapsToDevicePixels="True" Grid.Column="0" Orientation="Horizontal" Opacity="0">
                                                    <!--<Image x:Name="ImagePlayNow" SnapsToDevicePixels="True" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,1,0,0" Stretch="None" ToolTip="Sofort spielen" Source="Images/PreListen.png" MouseEnter="ImagePlayNow_MouseEnter" MouseLeave="ImagePlayNow_MouseLeave" MouseLeftButtonDown="ImagePlayNow_MouseLeftButtonDown" />-->
                                                    <!--<Image x:Name="ImagePlayNow" SnapsToDevicePixels="True" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,1,0,0" Stretch="None" ToolTip="Sofort spielen" Source="/CatalogView3D;component/Images/PlayNow.png" MouseEnter="ImagePlayNow_MouseEnter" MouseLeave="ImagePlayNow_MouseLeave" MouseLeftButtonDown="ImagePlayNow_MouseLeftButtonDown" />-->
                                                <!--<Image x:Name="ImagePlayNext" RenderOptions.BitmapScalingMode="NearestNeighbor" SnapsToDevicePixels="True" Margin="1,1,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Stretch="None" ToolTip="Als nächstes spielen" Source="/CatalogView3D;component/Images/PlayNext.png" MouseEnter="ImagePlayNext_MouseEnter" MouseLeave="ImagePlayNext_MouseLeave" MouseLeftButtonDown="ImagePlayNext_MouseLeftButtonDown" />
                                                <Image x:Name="ImagePlayLast" RenderOptions.BitmapScalingMode="NearestNeighbor" SnapsToDevicePixels="True" Margin="1,1,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Stretch="None" ToolTip="Als letztes spielen" Source="/CatalogView3D;component/Images/PlayLast.png"  MouseEnter="ImagePlayLast_MouseEnter" MouseLeave="ImagePlayLast_MouseLeave" MouseLeftButtonDown="ImagePlayLast_MouseLeftButtonDown" />
                                                <Image x:Name="ImagePlayPreListen" RenderOptions.BitmapScalingMode="NearestNeighbor" SnapsToDevicePixels="True" Margin="1,1,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" Stretch="None" ToolTip="Vorhören (Pre-Listen)" Source="/CatalogView3D;component/Images/PlayPreListen.png" MouseEnter="ImagePlayPreListen_MouseEnter" MouseLeave="ImagePlayPreListen_MouseLeave" MouseLeftButtonDown="ImagePlayPreListen_MouseLeftButtonDown" />-->
                                            </StackPanel>
                                            <TextBlock Grid.Column="1" VerticalAlignment="Center" Text="{Binding TrackNumber}"></TextBlock>
                                            <TextBlock Grid.Column="2" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Text="{Binding Title}"></TextBlock>
                                            <TextBlock Grid.Column="3" VerticalAlignment="Center" Text="{Binding Length, Converter={StaticResource lengthConverter}}"></TextBlock>
                                            <!--<hc:RatingUserControl Grid.Column="4" Value="{Binding Rating}" VerticalAlignment="Top" ValueChanged="RatingUserControl_ValueChanged" />-->
                                            <TextBlock Grid.Column="5" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Text="{Binding Artist}"></TextBlock>
                                            <TextBlock Grid.Column="6" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" Text="{Binding Composer}"></TextBlock>
                                        </Grid>
                                            <DataTemplate.Triggers>
                                                <DataTrigger Binding="{Binding Path=SoundFileExists}" Value="true">
                                                    <Setter TargetName="GridControl" Property="TextElement.Foreground" Value="#009900" />
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding Path=SoundFileExists}" Value="false">
                                                    <Setter TargetName="GridControl" Property="TextElement.Foreground" Value="Black" />
                                                    <!--<Setter TargetName="ImagePlayNow" Property="Opacity" Value="0.0" />
                                                    <Setter TargetName="ImagePlayNext" Property="Opacity" Value="0.0" />
                                                    <Setter TargetName="ImagePlayLast" Property="Opacity" Value="0.0" />
                                                    <Setter TargetName="ImagePlayPreListen" Property="Opacity" Value="0.0" />

                                                    <Setter TargetName="ImagePlayNow" Property="IsEnabled" Value="False" />
                                                    <Setter TargetName="ImagePlayNext" Property="IsEnabled" Value="False" />
                                                    <Setter TargetName="ImagePlayLast" Property="IsEnabled" Value="False" />
                                                    <Setter TargetName="ImagePlayPreListen" Property="IsEnabled" Value="False" />-->
                                                </DataTrigger>
                                                <EventTrigger SourceName="GridControl" RoutedEvent="TextBlock.MouseEnter">
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <ColorAnimation Storyboard.TargetName="GridControl"
                                                            Storyboard.TargetProperty="Background.Color"
                                                            From="#00A7B3FF" To="#A7B3FF" Duration="00:00:00.3" />
                                                        <DoubleAnimation Storyboard.TargetName="PlayButtons" 
                                                                         Storyboard.TargetProperty="Opacity"
                                                                         From="0" To="1" Duration="00:00:00.3" />
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger>
                                            <EventTrigger SourceName="GridControl" RoutedEvent="TextBlock.MouseLeave">
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <ColorAnimation Storyboard.TargetName="GridControl"
                                                            Storyboard.TargetProperty="Background.Color"
                                                            From="#A7B3FF" To="#00A7B3FF" Duration="00:00:00.3" />
                                                        <DoubleAnimation Storyboard.TargetName="PlayButtons" 
                                                                         Storyboard.TargetProperty="Opacity"
                                                                         From="1" To="0" Duration="00:00:00.3" />
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger>
                                        </DataTemplate.Triggers>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </Grid>

                    </StackPanel>
                    </Border>
                    <DataTemplate.Triggers>
                        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
                            <Setter Property="Background" Value="#f4f4ff" TargetName="ItemContainer"></Setter>
                        </Trigger>

                        <EventTrigger SourceName="GridRow" RoutedEvent="TextBlock.MouseEnter">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetName="GridRow"
                                                            Storyboard.TargetProperty="Background.Color"
                                                            From="#00A7B3FF" To="#33A7B3FF" Duration="00:00:00.3" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                        <EventTrigger SourceName="GridRow" RoutedEvent="TextBlock.MouseLeave">
                            <BeginStoryboard>
                                <Storyboard>
                                    <ColorAnimation Storyboard.TargetName="GridRow"
                                                            Storyboard.TargetProperty="Background.Color"
                                                            From="#33A7B3FF" To="#00A7B3FF" Duration="00:00:00.3" />
                                </Storyboard>
                            </BeginStoryboard>
                        </EventTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
        <!-- Wait indicator -->
        <Grid Name="GridLoadingCircle" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition></RowDefinition>
                <RowDefinition></RowDefinition>
            </Grid.RowDefinitions>
            <Canvas Grid.Row="0" Canvas.Left="21.75" Canvas.Top="14" Height="91.302" Width="102.197" >
                <Canvas.Resources>
                    <Style TargetType="Ellipse">
                        <Setter Property="Width" Value="15"/>
                        <Setter Property="Height" Value="15" />
                        <Setter Property="Fill" Value="#00FFFFFF" />
                    </Style>
                </Canvas.Resources>
                <Ellipse x:Name="_00" Canvas.Left="24.75" Canvas.Top="50"/>
                <Ellipse x:Name="_01" Canvas.Top="36" Canvas.Left="29.5"/>
                <Ellipse x:Name="_02" Canvas.Left="43.5" Canvas.Top="29.75"/>
                <Ellipse x:Name="_03" Canvas.Left="57.75" Canvas.Top="35.75"/>
                <Ellipse x:Name="_04" Canvas.Left="63.5" Canvas.Top="49.75" />
                <Ellipse x:Name="_05" Canvas.Left="57.75" Canvas.Top="63.5"/>
                <Ellipse x:Name="_06" Canvas.Left="43.75" Canvas.Top="68.75"/>
                <Ellipse x:Name="_07" Canvas.Top="63.25" Canvas.Left="30" />
                <Ellipse Stroke="{x:Null}" Width="39.5" Height="39.5" Canvas.Left="31.75" Canvas.Top="37" Fill="{x:Null}"/>
            </Canvas>
            <TextBlock Grid.Row="1" Text="Wird geladen..." FontSize="20" Foreground="Black" />
        </Grid>
    </Grid>
</UserControl>
